package com.bristua.barcode.order.biz;

import com.bristua.barcode.common.bean.PageBean;
import com.bristua.barcode.order.dao.TPayOrderMapper;
import com.bristua.barcode.order.model.TPayOrder;
import com.bristua.barcode.order.model.condition.AdminQueryOrderParams;
import com.bristua.barcode.order.model.condition.TPayOrderExample;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2019/8/24.
 */
@Service
public class QueryOrderListBiz {

    @Resource
    private TPayOrderMapper tPayOrderMapper;

    public PageBean<TPayOrder> queryOrderList(AdminQueryOrderParams queryOrderParams){
        TPayOrderExample tPayOrderExample = new TPayOrderExample();
        TPayOrderExample.Criteria criteria = tPayOrderExample.createCriteria();
        if(!StringUtils.isEmpty(queryOrderParams.getCustomerNo())){
            criteria.andCustomerNoEqualTo(queryOrderParams.getCustomerNo());
        }
        if(!StringUtils.isEmpty(queryOrderParams.getStartTime())){
            criteria.andCreateTimeGreaterThanOrEqualTo(queryOrderParams.getStartTime());
        }
        if(!StringUtils.isEmpty(queryOrderParams.getEndTime())){
            criteria.andCreateTimeLessThanOrEqualTo(queryOrderParams.getStartTime());
        }

        tPayOrderExample.setOrderByClause("create_time desc");
        Page<TPayOrder> objects = PageHelper.startPage(queryOrderParams.getPageNo(),queryOrderParams.getPageSize());
        tPayOrderMapper.selectByExample(tPayOrderExample);
        return new PageBean<TPayOrder>(objects);
    }
}
